/*
 * This source code is part of TWaver 4.0
 *
 * Serva Software PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 * Copyright 2002 - 2011 Serva Software. All rights reserved.
 */

package demo.alarm.mapping;

import twaver.Alarm;
import twaver.AlarmElementMapping;
import twaver.AlarmModelQuickFinder;
import twaver.DataBoxQuickFinder;
import twaver.Element;
import twaver.TDataBox;

public class CustomAlarmElementMapping implements AlarmElementMapping{
	
	private DataBoxQuickFinder elementFinder = null;
	private AlarmModelQuickFinder alarmFinder = null;
	
	public CustomAlarmElementMapping(TDataBox box){
		elementFinder = box.createClientPropertyFinder("mappingID");
		alarmFinder = box.getAlarmModel().createAlarmFinder("mappingID");
	}
	
	public Object getCorrespondingAlarms(TDataBox box, Element element) {
		if(element == null){
			return null;
		}
		Object mappingID = element.getClientProperty("mappingID");
		if(mappingID != null){
			return alarmFinder.find(mappingID);
		}
		return null;
	}

	public Object getCorrespondingElements(TDataBox box, Alarm alarm) {
		if(alarm == null){
			return null;
		}
		Object mappingID = alarm.getClientProperty("mappingID");
		if(mappingID != null){
			return elementFinder.find(mappingID);
		}
		return null;
	}



}